package a03_哈希;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * a06_四数相加2复习4
 * </p>
 *
 * @author flyduck
 * @since 2024/12/25
 */
public class a06_四数相加2复习4 {
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        Map<Integer,Integer> map = new HashMap<>();

        for (int i = 0; i < nums1.length; i++) {
            for (int j = 0; j < nums2.length; j++) {
                if(map.containsKey(nums1[i] + nums2[j])){
                    map.put(nums1[i] + nums2[j],map.get(nums1[i] + nums2[j])+1);
                }else {
                    map.put(nums1[i] + nums2[j],1);
                }
            }
        }

        int totalCount = 0;
        for (int m = 0; m < nums3.length; m++) {
            for (int n = 0; n < nums4.length; n++) {
                if(map.containsKey(0 - (nums3[m] + nums4[n]))){
                    totalCount = totalCount + map.get(0 - (nums3[m] + nums4[n]));
                }
            }
        }
        return totalCount;
    }
}
